package com.dsp.services.impl;


import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.core.util.DspUtil;
import com.core.util.GenericDAO;
import com.core.util.GenericServiceHibernate;
import com.dsp.bean.InsureResultsSub;
import com.dsp.dao.InsureResultsSubDAO;
import com.dsp.services.InsureResultsSubService;

@Service("insureResultsSubService")
public class InsureResultsSubServiceImpl extends GenericServiceHibernate<InsureResultsSub, Long> implements InsureResultsSubService {

	@Autowired
	private InsureResultsSubDAO insureResultsSubDAO;
	
	@Resource( name = "insureResultsSubDAO")
	public void setDao(GenericDAO<InsureResultsSub, Serializable> dao) {
		super.setDao(dao);
	}

	/**
	 * @return the insureResultsSubDAO
	 */
	public InsureResultsSubDAO getInsureResultsSubDAO() {
		return insureResultsSubDAO;
	}

	/**
	 * @param insureResultsSubDAO the insureResultsSubDAO to set
	 */
	public void setInsureResultsSubDAO(InsureResultsSubDAO insureResultsSubDAO) {
		this.insureResultsSubDAO = insureResultsSubDAO;
	}

	@Override
	public void delete(Long pk) {
		this.insureResultsSubDAO.delete(pk);
	}

	@Override
	public List<InsureResultsSub> setFooter(List<InsureResultsSub> rows) {
		List<InsureResultsSub> footer = new ArrayList<InsureResultsSub>();
		BigDecimal personalBig = new BigDecimal(0); 
		BigDecimal companyBig  = new BigDecimal(0);
		InsureResultsSub irs = null;
		for(int i = 0 ; rows != null && i < rows.size(); i++){
			irs = (InsureResultsSub)rows.get(i);
			if(irs.getInsureType() == 1) {
				personalBig = personalBig.add(irs.getInsureMoney());
			} else if (irs.getInsureType() == 2) {
				companyBig  = companyBig.add(irs.getInsureMoney());
			}
		}
		InsureResultsSub foot = new InsureResultsSub();
		foot.setInsureItem(-1L);//个人
		foot.setInsureMoney(personalBig);
		footer.add(foot);
		foot = new InsureResultsSub();
		foot.setInsureItem(-2L);
		foot.setInsureMoney(companyBig);
		footer.add(foot);
		return footer;
	}
}
